import ldap


class StudentDaoLDAP(object):
    __connector = None

    #for example 'ou=students,ou=eaiie,ou=faculties,o=agh'
    __context = None

    def __init__(self, connector, configReader):
        configReader.read('config/labmin.conf')
        
        self.__connector = connector
        self.__context = configReader.get('LDAP', 'search_context')

    def setContext(self, context):
        self.__context = context
        
    def getContext(self):
        return self.__context

    def searchStudent(self, email):
        filter='(mail=' + email + ')'
        return self.__connector.handleSearch(self.__context, ldap.SCOPE_SUBTREE, filter, ['cn', 'mail', 'faculty', 'year'])